package com.sch.hospital.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.CrossOrigin;
import com.sch.hospital.domain.Result;
import com.sch.hospital.domain.Department;
import com.sch.hospital.service.IDepartmentService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 医院部门Controller
 * 
 * @author ruoyi
 * @date 2025-06-30
 */
@Tag(name = "医院部门相关接口")
@RestController
@RequestMapping("/system/department")
@CrossOrigin
public class DepartmentController
{
    @Autowired
    private IDepartmentService departmentService;

    /**
     * 查询医院部门列表
     */
    @Operation(summary = "查询科室列表")
    @GetMapping("/list")
    public Result list(Department department)
    {
        List<Department> list = departmentService.selectDepartmentList(department);
        return Result.success(list);
    }

    /**
     * 获取医院部门详细信息
     */
    @Operation(summary = "获取科室详细信息")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return Result.success(departmentService.selectDepartmentById(id));
    }

    /**
     * 新增医院部门
     */
    @Operation(summary = "新增科室")
    @PostMapping
    public Result add(@RequestBody Department department)
    {
        int rows = departmentService.insertDepartment(department);
        return rows > 0 ? Result.success() : Result.error("新增医院部门失败");
    }

    /**
     * 修改医院部门
     */
    @Operation(summary = "修改科室")
    @PutMapping
    public Result edit(@RequestBody Department department)
    {
        int rows = departmentService.updateDepartment(department);
        return rows > 0 ? Result.success() : Result.error("修改医院部门失败");
    }

    /**
     * 删除医院部门
     */
	@Operation(summary = "删除科室")
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        int rows = departmentService.deleteDepartmentByIds(ids);
        return rows > 0 ? Result.success() : Result.error("删除医院部门失败");
    }
}
